﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Messaging;
using System.Text;
using System.Windows;

namespace BeerManagementSystem
{
    internal class Ranking
    {
        private static DateTime _dayStart, _monthStart;

        private static int _totalBeerCount, _monthBeerCount, _dayBeerCount;

        private User[] _totalRanking, _monthRanking, _dayRanking;

        public Ranking(int countTotal, int countMonth, int countDay)
        {
            UpdateCurrentDate();
            _totalRanking = new User[countTotal];
            _monthRanking = new User[countMonth];
            _dayRanking = new User[countDay];
        }

        public static void UpdateCurrentDate()
        {
            if (DateTime.Now.TimeOfDay.Hours < 12)
                _dayStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day -1, 12, 0, 0);
            else
                _dayStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day   , 12, 0, 0);

            if (DateTime.Now.TimeOfDay.Hours < 12 && DateTime.Now.Day == 1)
                _monthStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month - 1, 1, 12, 0, 0);
            else
                _monthStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1, 12, 0, 0);
        }

        public static bool IsNotToday(DateTime lastTransactionDateTime)
        {
            return (lastTransactionDateTime < _dayStart);
        }

        public static bool IsNewMonth(DateTime lastTransactionDateTime)
        {
            return lastTransactionDateTime < _monthStart;
        }

        public User[] GetRankingTotal()
        {
            return _totalRanking;
        }

        public User[] GetRankingMonth()
        {
            return _monthRanking;
        }

        public User[] GetRankingDay()
        {
            return _dayRanking;
        }

        public void SetRankingTotal(User[] rank)
        {
            _totalRanking = rank;
        }

        public void SetRankingMonth(User[] rank)
        {
            _monthRanking = rank;
        }

        public void SetRankingDay(User[] rank)
        {
            _dayRanking = rank;
        }

        public static int GetTotalBeerCount()
        {
            return _totalBeerCount;
        }

        public static void IncrementBeerTotalCount()
        {
            _totalBeerCount++;
        }

        public static void SetTotalBeerCount(int count)
        {
            _totalBeerCount = count;
        }

        internal DateTime GetDayStart()
        {
            return _dayStart;
        }

        public static void SetMonthBeerCount(int monthBeerCount)
        {
            _monthBeerCount = monthBeerCount;
        }

        public static void SetDayBeerCount(int count)
        {
            _dayBeerCount = count;
        }

        public static int GetMonthBeerCount()
        {
            return _monthBeerCount;
        }

        public static int GetDayBeerCount()
        {
            return _dayBeerCount;
        }

        public static void DecrementBeerTotalCount()
        {
            _totalBeerCount--;
        }
    }
}
